'use strict'

//引入需要用到的模块
let Koa =require('koa');
let router = require('koa-router')();
let bodyparser = require('koa-bodyparser');
const ip = require('./ip');

//初始化Koa对象
let app = new Koa();

//安装中间件，先注册bodyparser，再注册router
app.use(bodyparser());
app.use(router.routes());

for(let r in ip){
    let type = ip[r][0];
    let oi = ip[r][1];
    if(type === 'get'){
        router.get(r,oi);
    }else{
        router.post(r,oi);
    }
}

//监听端口
let port = 8080;
app.listen(port);

//打印服务器运行地址
console.log(`http://127.0.0.1:${port}`);